@extends('layouts.app')
@section('title', '社区系统-分类管理')
@section('content')
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <button class="layui-btn layuiadmin-btn-tags" data-type="add">添加</button>
        </div>
        <div class="layui-card-body">
            <table id="LAY-app-content-categories" lay-filter="LAY-app-content-categories"></table>
            <script type="text/html" id="buttonTpl">
                {{#  if(d.status){ }}
                <button class="layui-btn layui-btn-xs">启用</button>
                {{#  } else { }}
                <button class="layui-btn layui-btn-primary layui-btn-xs">禁用</button>
                {{#  } }}
            </script>
            <script type="text/html" id="layuiadmin-app-cont-categoriesbar">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                        class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                        class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script src="/static/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'forum', 'table'], function () {
        var $ = layui.$
            , admin = layui.admin
            , view = layui.view
            , table = layui.table
            , form = layui.form;

        var active = {
            add: function () {
                admin.popup({
                    title: '添加分类'
                    , area: ['500px', '450px']
                    , id: 'LAY-popup-content-categories'
                    , success: function (layero, index) {
                        view(this.id).render('app/content/categoryform').done(function () {
                            form.render(null, 'layuiadmin-form-categories');

                            //监听提交
                            form.on('submit(layuiadmin-app-categories-submit)', function (data) {
                                admin.req({
                                    url: layui.setter.host + "/article_category"
                                    , data: data.field
                                    , type: "post"
                                    , done: function (res) {
                                        if (res.code === 0) {
                                            layer.msg(res.msg, {icon: 6});
                                            table.reload('LAY-app-content-categories'); //数据刷新
                                            layer.close(index); //关闭弹层
                                        } else {
                                            layer.msg(res.msg, {icon: 5});
                                        }
                                    }
                                });
                            });
                        });
                    }
                });
            }
        }
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>
